﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Lswweb.Model;
using Lswweb.Domain;
using FredCK.FCKeditorV2;
using System.Configuration;

namespace Lswweb.Controls
{
    public class MessageAdd : SkinnedWebControl
    {
        private TextBox tbxTitle;
        private TextBox tbxEmail;
        private TextBox tbxPhone;
        private TextBox tbxBody;
        private TextBox tbxLinkMan;
        private TextBox tbxFax;
        private TextBox tbxMobile;
        private Button btnConfirm;

        protected override void InitializeSkin(Control skin)
        {
            tbxTitle = (TextBox)skin.FindControl("tbxTitle");
            tbxEmail = (TextBox)skin.FindControl("tbxEmail");
            tbxPhone = (TextBox)skin.FindControl("tbxPhone");
            tbxBody = (TextBox)skin.FindControl("tbxBody");
            tbxLinkMan = (TextBox)skin.FindControl("tbxLinkMan");
            tbxFax = (TextBox)skin.FindControl("tbxFax");
            tbxMobile = (TextBox)skin.FindControl("tbxMobile");

            btnConfirm = (Button)skin.FindControl("btnConfirm");

            btnConfirm.Click += new EventHandler(btnConfirm_Click);
        }

        void btnConfirm_Click(object sender, EventArgs e)
        {
            MessageInfo info = new MessageInfo();

            info.Content = tbxBody.Text.Trim();
            info.Email = tbxEmail.Text.Trim();
            info.Fax = tbxFax.Text.Trim();
            info.IsRead = false;
            info.LinkMan = tbxLinkMan.Text.Trim();
            info.Mobile = tbxMobile.Text.Trim();
            info.Phone = tbxPhone.Text.Trim();

            info.Content += ProductStorage.BuilderHtmlTableByCart(ShoppingCartFactory.GetShoppingCart());
            ShoppingCartFactory.GetShoppingCart().Clear();

            Messages.Insert(info);
        }

        protected override string DefaultSkinFilename
        {
            get { return "Message/MessageAdd.ascx"; }
        }
    }
}
